package com.CNMedical.web.controller.system.applet;


import com.CNMedical.common.annotation.Anonymous;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.R;
import com.CNMedical.system.domain.entity.AppletQuestionOption;
import com.CNMedical.system.domain.vo.AppletExamScoreVO;
import com.CNMedical.system.domain.vo.AppletQuestionVO;
import com.CNMedical.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "考试接口")
@Anonymous
@RestController
@RequestMapping("/applet/exam")
public class ExamController extends BaseController {

    @Resource
    private IAppletQuestionService questionService;

    @Resource
    private IAppletQuestionOptionService questionOptionService;

    @Resource
    private IAppletQuestionAnswerService appletQuestionAnswerService;

    @Resource
    private IAppletExamScoreService appletExamScoreService;

    /**
     * 通过知识id获取该知识下的题目
     *
     * @date 2023-03-30
     */
    @ApiOperation("通过知识id获取该知识下的题目")
    @GetMapping("/getAllQuestionByKnowledgeId/{knowledgeId}")
    public R<List<AppletQuestionVO>> getAllQuestionByKnowledgeId(@PathVariable String knowledgeId) {
        return R.ok(questionService.getAllQuestionByKnowledgeId(knowledgeId));
    }

    /**
     * 通过试题id获取试题选项
     *
     * @date 2023-03-30
     */
    @ApiOperation("通过试题id获取试题选项")
    @GetMapping("/getAllOptionsByQuestionId/{questionId}")
    public R<List<AppletQuestionOption>> getAllOptionsByQuestionId(@PathVariable String questionId) {
        return R.ok(questionOptionService.getAllOptionsByQuestionId(questionId));
    }

    /**
     * 交卷
     *
     * @date 2023-03-30
     */
    @ApiOperation("交卷")
    @PostMapping("/finishExam")
    public R finishExam(@RequestParam String knowledgeId, @RequestParam String userId) {
        appletExamScoreService.countScore(knowledgeId, userId);
        return R.ok();
    }

    /**
     * 用户提交各个试题的答案
     *
     * @date 2023-03-30
     */
    @ApiOperation("用户提交各个试题的答案")
    @PostMapping("/putQuestionAnswer")
    public R putQuestionAnswer(@RequestParam String questionId , @RequestParam String optionId, @RequestParam String userId) {
        appletQuestionAnswerService.putQuestionAnswer(questionId,optionId,userId);
        return R.ok();
    }

    /**
     * 获取已完成的考试
     *
     * @date 2023-03-30
     */
    @ApiOperation("获取用户已完成的考试")
    @GetMapping("/getFinishExamList/{userId}")
    public R<List<AppletExamScoreVO>> getFinishExamList(@PathVariable String userId) {
        return R.ok(appletExamScoreService.getFinishExamList(userId));
    }

}
